package ebusiness.ebusiness.Controllers;

import ebusiness.ebusiness.Dao.UserDao.UserQueryVO;
import ebusiness.ebusiness.Entity.Address;
import ebusiness.ebusiness.Entity.UserEntity.RegisteUser;
import ebusiness.ebusiness.Entity.UserEntity.User;
import ebusiness.ebusiness.Entity.UserEntity.UserDetail;
import ebusiness.ebusiness.Entity.UserEntity.Visitor;
import ebusiness.ebusiness.Mapper.PathUtil.WebPath;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@RestController
public class PersonInfoController
{

    @RequestMapping(path = WebPath.PersonINFO,method = RequestMethod.POST)
    public String modifyPersonInfo(HttpSession session, String c_name, String customer_email,
                                   String customer_phone, String customer_sex,String customer_birth, String customer_hobby,
                                   String customer_num,String customer_marriage,String customer_education,double customer_income,
                                   String customer_job,String customer_img) throws Exception {

        int id = (int) session.getAttribute("user");
        UserDetail user = null;
        user.setId(id);
        user.setC_name(c_name);
        user.setCustomer_email(customer_email);
        user.setCustomer_phone(customer_phone);
        user.setCustomer_sex(customer_sex);
        user.setCustomer_hobby(customer_hobby);
        user.setCustomer_num(customer_num);
        user.setCustomer_marrige(customer_marriage);
        user.setCustomer_education(customer_education);
        user.setCustomer_mincome(customer_income);
        user.setCustomer_job(customer_job);
        user.setCustomer_img(customer_img);
        user.setCustomer_birth(customer_birth);
        UserQueryVO userQueryVO = new UserQueryVO();
        UserDetail personInfo = userQueryVO.getUserDetailByID(id);
        if(personInfo == null){
            try {
                userQueryVO.addPersonInfo(user);
            }catch (Exception e){
                return "0";
            }
            return "1";
        }else{
            try {
                userQueryVO.modifyPersonInfo(user);
            }catch (Exception e){
                return "0";
            }
            return "1";
        }

    }
}
